﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace _4mvcBlog.Core
{
    /// <summary>
    /// 测试用户只可以查看
    /// </summary>
    public class TestUserAuthorizeAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            string user = filterContext.HttpContext.User.Identity.Name;
            if (//!filterContext.HttpContext.Request.HttpMethod.Equals("get", StringComparison.OrdinalIgnoreCase) &&
                !string.IsNullOrEmpty(user) &&
                user.Equals("test", StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("测试用户不可以进行该操作。");
            }

            //base.OnAuthorization(filterContext);
        }
    }
}
